package com.acme.benchmarks;

import com.acme.HashMapFactory;

import java.util.Map;


public class MemoryBenchmark extends Benchmark {



    public MemoryBenchmark(int iterations, int growFactor, HashMapFactory factory) {
        super(iterations, growFactor, factory);
    }



    protected void runIteration(int iterationSize){
        System.gc();
        long mem = getFreeMemory();
        mem = getFreeMemory();

        Map<Integer, Integer> hashMap =  generateMap(iterationSize);

        System.gc();
        mem = mem - getFreeMemory();

        int perMem = (int) (mem / hashMap.size());

        log(iterationSize + ":" + perMem);
        accString += ("" + hashMap.size()).substring(0, 1);
    }

    private static long getFreeMemory() {
        System.gc();
        return Runtime.getRuntime().freeMemory();
    }

}
